package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.PartyRsDyjbxx;
import com.yuncheng.oaApi.service.IPartyRsDyjbxxService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 党员基本信息
 * @Author: lhb
 * @Date: 2023-11-30
 * @Version: V1.0
 */
@Api(tags = "DW_党员基本信息接口")
@RestController
@RequestMapping("/api/spzx-oa/partyRsDyjbxx")
public class PartyRsDyjbxxController extends BaseController<PartyRsDyjbxx, IPartyRsDyjbxxService> {

    private static final Logger log = LoggerFactory.getLogger(PartyRsDyjbxxController.class);

    @Resource
    private IPartyRsDyjbxxService partyRsDyjbxxService;

    @AutoLog(value = "党员基本信息-分页列表查询")
    @ApiOperation(value = "党员基本信息-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(PartyRsDyjbxx partyRsDyjbxx,
                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<PartyRsDyjbxx> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.like(StringUtils.isNotBlank(partyRsDyjbxx.getFrdzt()), PartyRsDyjbxx::getFrdzt,partyRsDyjbxx.getFrdzt());
        queryWrapper.like(StringUtils.isNotBlank(partyRsDyjbxx.getFxm()), PartyRsDyjbxx::getFxm,partyRsDyjbxx.getFxm());

        Page<PartyRsDyjbxx> page = new Page<>(pageNo, pageSize);
        IPage<PartyRsDyjbxx> pageList = partyRsDyjbxxService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }


    @AutoLog(value = "党员基本信息-添加")
    @ApiOperation(value = "党员基本信息-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody PartyRsDyjbxx partyRsDyjbxx) {
        HttpResult<String> result = new HttpResult(true);
        partyRsDyjbxxService.save(partyRsDyjbxx);
        result.setResult(partyRsDyjbxx.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    @AutoLog(value = "党员基本信息-编辑")
    @ApiOperation(value = "党员基本信息-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody PartyRsDyjbxx partyRsDyjbxx) {
        partyRsDyjbxxService.updateById(partyRsDyjbxx);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    @AutoLog(value = "党员基本信息-通过id删除")
    @ApiOperation(value = "党员基本信息-通过id删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        partyRsDyjbxxService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "党员基本信息-批量删除")
    @ApiOperation(value = "党员基本信息-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        partyRsDyjbxxService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    @AutoLog(value = "党员基本信息-通过id查询")
    @ApiOperation(value = "党员基本信息-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        PartyRsDyjbxx partyRsDyjbxx = partyRsDyjbxxService.getById(id);
        return HttpResult.ok(partyRsDyjbxx);
    }


}
